package selenium;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

public class SeleniumBase {

	private WebDriver driver;
	protected String baseUrl;

	public SeleniumBase() {
		super();
	}

	@BeforeClass
	public void setUpDriver() throws Exception {
		//driver = new FirefoxDriver();
		driver = new HtmlUnitDriver();
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	
	}

	@AfterClass
	public void tearDown() throws Exception {
		driver.quit();
		
	}

	protected void insertText(By by, String text){
		WebElement element = driver.findElement(by);
		element.clear();
		element.sendKeys(text);
	}
	
	protected void open(String url) {
		driver.get(url);
	}

	protected void click(By by) {
		driver.findElement(by).click();
	}

	protected void assertLinkTextEquals(String expectedText) {
		assertEquals(expectedText, driver
				.findElement(By.linkText(expectedText)).getText());
	}

	protected void assertTextPresent(String expectedText) {
		assertTrue(driver.getPageSource().contains(expectedText));
	}
}